import {Injectable} from '@angular/core';
import {HttpUtilService} from "../../../../../services/http/http-util.service";
import {BarnMenu} from "../entity/barn-menu";
import {Observable} from "rxjs";

@Injectable({
  providedIn: 'root'
})
export class BarnMenuService {

  private prefix = "system/menu/"

  constructor(private http: HttpUtilService) {
  }

  /**
   * 保存数据
   * @param data
   * @param handleError
   */
  save(data: BarnMenu, handleError = true): Observable<BarnMenu> {
    return this.http.post<BarnMenu>(this.prefix + "save", data, handleError)
  }

  /**
   * 查询一个
   * @param pid
   * @param handleError
   */
  getById(pid: string, handleError = true): Observable<BarnMenu> {
    return this.http.get<BarnMenu>(this.prefix + "getById/" + pid, handleError);
  }

  /**
   * 查询所有
   */
  getAll(): Observable<BarnMenu[]> {
    return this.http.get<BarnMenu[]>(this.prefix + "getAll", true,null);
  }

  /**
   * 删除
   * @param pid
   * @param handleError
   */
  deleteById(pid: string, handleError = true) {
    return this.http.get(this.prefix + "delete/" + pid, handleError);
  }
}
